@@ -241,7 +241,22 @@ h2 .scenario, a span.label.scenario {
|
||
| 241 | 241 |
width: 200px; |
| 242 | 242 |
} |
| 243 | 243 |
|
| 244 |
-.btn-auth {
|
|
| 244 |
+$services: twitter 37signals github tumblr; |
|
| 245 |
+$service-colors: #55acee #8fc857 #444444 #2c4762; |
|
| 246 |
+ |
|
| 247 |
+@mixin services {
|
|
| 248 |
+ @each $service in $services {
|
|
| 249 |
+ $i: index($services, $service); |
|
| 250 |
+ $service-color: nth($service-colors, $i); |
|
| 251 |
+ |
|
| 252 |
+ &.service-#{$service} {
|
|
| 253 |
+ color: #fff; |
|
| 254 |
+ background-color: $service-color; |
|
| 255 |
+ } |
|
| 256 |
+ } |
|
| 257 |
+} |
|
| 258 |
+ |
|
| 259 |
+.btn-service {
|
|
| 245 | 260 |
position: relative; |
| 246 | 261 |
padding-left: 40px; |
| 247 | 262 |
$border-color: rgba(0,0,0,0.2); |
@@ -260,18 +275,9 @@ h2 .scenario, a span.label.scenario {
|
||
| 260 | 275 |
border-right: 1px solid $border-color; |
| 261 | 276 |
} |
| 262 | 277 |
|
| 263 |
- &.btn-auth-twitter {
|
|
| 264 |
- color: #fff; |
|
| 265 |
- background-color: #55acee; |
|
| 266 |
- } |
|
| 267 |
- |
|
| 268 |
- &.btn-auth-37signals {
|
|
| 269 |
- color: #fff; |
|
| 270 |
- background-color: #8fc857; |
|
| 271 |
- } |
|
| 278 |
+ @include services; |
|
| 279 |
+} |
|
| 272 | 280 |
|
| 273 |
- &.btn-auth-github {
|
|
| 274 |
- color: #fff; |
|
| 275 |
- background-color: #444; |
|
| 276 |
- } |
|
| 281 |
+.label-service {
|
|
| 282 |
+ @include services; |
|
| 277 | 283 |
} |
@@ -41,12 +41,34 @@ module ApplicationHelper |
||
| 41 | 41 |
end |
| 42 | 42 |
end |
| 43 | 43 |
|
| 44 |
- def icon_for_service(service) |
|
| 45 |
- case service.to_sym |
|
| 44 |
+ def omniauth_provider_icon(provider) |
|
| 45 |
+ case provider.to_sym |
|
| 46 | 46 |
when :twitter, :tumblr, :github |
| 47 |
- "<i class='fa fa-#{service}'></i>".html_safe
|
|
| 47 |
+ content_tag :i, '', class: "fa fa-#{provider}"
|
|
| 48 | 48 |
else |
| 49 |
- "<i class='fa fa-lock'></i>".html_safe |
|
| 49 |
+ content_tag :i, '', class: "fa fa-lock" |
|
| 50 | 50 |
end |
| 51 | 51 |
end |
| 52 |
+ |
|
| 53 |
+ def omniauth_provider_name(provider) |
|
| 54 |
+ t("devise.omniauth_providers.#{provider}")
|
|
| 55 |
+ end |
|
| 56 |
+ |
|
| 57 |
+ def omniauth_button(provider) |
|
| 58 |
+ link_to [ |
|
| 59 |
+ omniauth_provider_icon(provider), |
|
| 60 |
+ content_tag(:span, "Authenticate with #{omniauth_provider_name(provider)}")
|
|
| 61 |
+ ].join.html_safe, user_omniauth_authorize_path(provider), class: "btn btn-default btn-service service-#{provider}"
|
|
| 62 |
+ end |
|
| 63 |
+ |
|
| 64 |
+ def service_label_text(service) |
|
| 65 |
+ "#{omniauth_provider_name(service.provider)} - #{service.name}"
|
|
| 66 |
+ end |
|
| 67 |
+ |
|
| 68 |
+ def service_label(service) |
|
| 69 |
+ content_tag :span, [ |
|
| 70 |
+ omniauth_provider_icon(service.provider), |
|
| 71 |
+ service_label_text(service) |
|
| 72 |
+ ].join.html_safe, class: "label label-default label-service service-#{service.provider}"
|
|
| 73 |
+ end |
|
| 52 | 74 |
end |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 |
<% if agent.try(:oauthable?) %> |
| 2 | 2 |
<div class="form-group type-select"> |
| 3 | 3 |
<%= label_tag :service %> |
| 4 |
- <%= select_tag 'agent[service_id]', options_for_select(agent.valid_services_for(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, agent.service_id), class: 'form-control' %>
|
|
| 4 |
+ <%= select_tag 'agent[service_id]', options_for_select(agent.valid_services_for(current_user).collect { |s| [service_label_text(s), s.id] }, agent.service_id), class: 'form-control' %>
|
|
| 5 | 5 |
</div> |
| 6 | 6 |
<% end %> |
@@ -107,6 +107,13 @@ |
||
| 107 | 107 |
</p> |
| 108 | 108 |
<% end %> |
| 109 | 109 |
|
| 110 |
+ <% if @agent.try(:oauthable?) %> |
|
| 111 |
+ <p> |
|
| 112 |
+ <b>Service:</b> |
|
| 113 |
+ <%= service_label(@agent.service) %> |
|
| 114 |
+ </p> |
|
| 115 |
+ <% end %> |
|
| 116 |
+ |
|
| 110 | 117 |
<% if @agent.can_receive_events? %> |
| 111 | 118 |
<p> |
| 112 | 119 |
<b>Event sources:</b> |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 |
for guidance. |
| 13 | 13 |
</p> |
| 14 | 14 |
<%- Devise.omniauth_providers.each { |provider| -%>
|
| 15 |
- <p><%= link_to user_omniauth_authorize_path(provider), class: "btn btn-default btn-auth btn-auth-#{provider}" do %><%= icon_for_service(provider) %><span>Authenticate with <%= t("devise.omniauth_providers.#{provider}") %></span><% end %></p>
|
|
| 15 |
+ <p><%= omniauth_button(provider) %></p> |
|
| 16 | 16 |
<%- } -%> |
| 17 | 17 |
<hr> |
| 18 | 18 |
|
@@ -27,9 +27,9 @@ |
||
| 27 | 27 |
|
| 28 | 28 |
<% @services.each do |service| %> |
| 29 | 29 |
<tr> |
| 30 |
- <td><%= service.provider %></td> |
|
| 30 |
+ <td><%= omniauth_provider_name(service.provider) %></td> |
|
| 31 | 31 |
<td><%= service.name %></td> |
| 32 |
- <td><%= service.global ? 'Yes' : 'No' %></td> |
|
| 32 |
+ <td><%= yes_no(service.global) %></td> |
|
| 33 | 33 |
<td> |
| 34 | 34 |
<div class="btn-group btn-group-xs"> |
| 35 | 35 |
<% if service.global %> |
@@ -121,23 +121,23 @@ describe ApplicationHelper do |
||
| 121 | 121 |
end |
| 122 | 122 |
end |
| 123 | 123 |
|
| 124 |
- describe '#icon_for_service' do |
|
| 124 |
+ describe '#omniauth_provider_icon' do |
|
| 125 | 125 |
it 'returns a correct icon tag for Twitter' do |
| 126 |
- icon = icon_for_service(:twitter) |
|
| 126 |
+ icon = omniauth_provider_icon(:twitter) |
|
| 127 | 127 |
expect(icon).to be_html_safe |
| 128 | 128 |
elem = Nokogiri(icon).at('i.fa.fa-twitter')
|
| 129 | 129 |
expect(elem).to be_a Nokogiri::XML::Element |
| 130 | 130 |
end |
| 131 | 131 |
|
| 132 | 132 |
it 'returns a correct icon tag for GitHub' do |
| 133 |
- icon = icon_for_service(:github) |
|
| 133 |
+ icon = omniauth_provider_icon(:github) |
|
| 134 | 134 |
expect(icon).to be_html_safe |
| 135 | 135 |
elem = Nokogiri(icon).at('i.fa.fa-github')
|
| 136 | 136 |
expect(elem).to be_a Nokogiri::XML::Element |
| 137 | 137 |
end |
| 138 | 138 |
|
| 139 | 139 |
it 'returns a correct icon tag for other services' do |
| 140 |
- icon = icon_for_service(:'37signals') |
|
| 140 |
+ icon = omniauth_provider_icon(:'37signals') |
|
| 141 | 141 |
expect(icon).to be_html_safe |
| 142 | 142 |
elem = Nokogiri(icon).at('i.fa.fa-lock')
|
| 143 | 143 |
expect(elem).to be_a Nokogiri::XML::Element |